Ext.define('Ssimgres.controller.Menu', {
	extend : 'Ext.app.Controller',
	views : ['menu.Menu', 'menu.Visor'],
	stores : ['Menu'],
	refs : [{
		ref : 'visorView',
		selector : 'visorView'
	}],
	init : function() {
		this.control({
			'menuView button[action=btnCerrarSesion]' : {
				click : this.cerrarSesion
			},
			'menuView button[action=btnInicio]' : {
				click : this.inicio
			},
			'menuView' : {
				itemclick : this.addTab
			}
		});
	},
	cerrarSesion : function() {
		window.location = '/servicio_sesion/cerrar'
	},
	inicio : function() {
		window.location = '/'
	},
	addTab : function(node, record, item, index, e) {
		var id = record.get('id');
		var tap = Ext.getCmp(id);
		if (!Ext.isEmpty(tap)) {
			this.getVisorView().setActiveTab(tap);
		} else {
			if (!Ext.isEmpty(id)) {
				tab = Ext.widget(id, {
					id : id
				});
				this.getVisorView().add(tab);
				this.getVisorView().setActiveTab(tab);
			}

		}
	}
});
